package com.lwt.gulimall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwt.gulimall.product.entity.CategoryBrandRelation;
import com.lwt.gulimall.product.mapper.CategoryBrandRelationMapper;
import com.lwt.gulimall.product.service.BrandService;
import com.lwt.gulimall.product.service.CategoryBrandRelationService;
import com.lwt.gulimall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
*
*/
@Service
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelation>
implements CategoryBrandRelationService{
    @Autowired
    private BrandService brandService;

    @Autowired
    private CategoryService categoryService;

    @Override
    public List<CategoryBrandRelation> getBrandRelateCategory(Long brandId) {
        return this.list(new LambdaQueryWrapper<CategoryBrandRelation>().eq(CategoryBrandRelation::getBrandId,brandId));
    }

    @Override
    public void saveData(CategoryBrandRelation categoryBrandRelation) {
        categoryBrandRelation.setBrandName(brandService.getById(categoryBrandRelation.getBrandId()).getName());
        categoryBrandRelation.setCatelogName(categoryService.getById(categoryBrandRelation.getCatelogId()).getName());
        this.save(categoryBrandRelation);
    }
}
